#ifndef __SLIST_H
#define __SLIST_H
#include "stdtype.h"

/* single list definition */
typedef struct mx_slist
{
    struct mx_slist* next;
} mx_slist_t, *mx_slist_pt;

/**
 * this function will iterate the specified single list
 * @prototype: void mx_slist_foreach (mx_slist_pt, <l>, {...});
 * @note: do not change the struct of single list, like remove or insert
 */
#define mx_slist_foreach(sl, l, ...) {  \
    mx_slist_pt l; mx_bool_t flag = mx_true;    \
    for (l = sl; l != sl || ({mx_bool_t rf = mx_false; if (flag) { flag = mx_false; rf = mx_true; } rf;}); l = l->next) {__VA_ARGS__}}

/* this function will initiaize the specified single list */
void mx_slist_init (mx_slist_pt sl);
/* this function will insert the single list before the base */
void mx_slist_insert_before (mx_slist_pt tsl, mx_slist_pt sl);
/* this function will insert the single list after the base */
void mx_slist_insert_after (mx_slist_pt tsl, mx_slist_pt sl);
/* this function will remove the specified single list node */
void mx_slist_remove (mx_slist_pt sl);
/* this function will return the length of specified single list */
mx_usize_t mx_slist_count (mx_slist_pt sl);

#endif
